/*
 * StaticDrawController.cpp
 *
 *  Created on: Nov 21, 2011
 *      Author: rudi
 */
#include "StaticDrawController.h"
#include "MainPanel.h"
#include "MainFrame.h"
#include "Configuration.h"
#include "App.h"

StaticDrawController::StaticDrawController(SmartPointer<wxBitmap> bitmap, bool refresh): mBitmap(bitmap)
{
	if(true == refresh)
		this->refreshImage(true);
//	/*wxLogWindow* log = */new wxLogWindow(NULL, wxT("DrawController Log"));
}

/*virtual*/
StaticDrawController::~StaticDrawController()
{
	// Nothing to do yet
}

//
// Methods inherited from Controller
//

void StaticDrawController::handleMouseDown(const wxPoint& /*position*/)
{
	// Nothing to do
}

void StaticDrawController::handleMouseUp(const wxPoint& /*position*/)
{
	// Nothing to do
}

bool StaticDrawController::handleMouseMotion(const wxPoint& /*position*/)
{
	// Nothing to do
	return false;
}

const wxBitmap& StaticDrawController::getBitmapToPaint() const
{
	return *mBitmap;
}

wxBitmap& StaticDrawController::getBitmapToDraw()
{
	return *mBitmap;
}

//
// Methods inherited from DrawController
//

SmartPointer<Vehicle> StaticDrawController::getActualVehicle() const
{
	// Nothing to do
	return NULL;
}

SmartPointer<Vehicle> StaticDrawController::getRemoteVehicle() const
{
	// Nothing to do
	return NULL;
}

SmartPointer<std::vector<wxPoint> > StaticDrawController::getActualVehicleArrows()
{
	// Nothing to do
	return NULL;
}

SmartPointer<std::vector<wxPoint> > StaticDrawController::getRemoteVehicleArrows()
{
	// Nothing to do
	return NULL;
}

void StaticDrawController::refreshImage(bool doRefresh, MainPanel* mainPanel)
{
	// Get the MainPanel to be able to force a refresh
	if(NULL == mainPanel)
		mainPanel = wxGetApp().getMainFrame()->getMainPanel();
	this->paintDots();
	mainPanel->SetClientSize(mBitmap->GetWidth(), mBitmap->GetHeight());
	if(true == doRefresh)
		mainPanel->Refresh();
}

/**
 * PRIVATE METHODS
 */

void StaticDrawController::paintDots()
{
	int dotSize = wxGetApp().getConfiguration()->getDotSize();
	wxMemoryDC dc;

	dc.SelectObject(*mBitmap);
	this->setPen(dc, WxUtils::RED);
	// Insert the dots to the picture
	for(int i = 0; i < mBitmap->GetWidth(); i += dotSize)
	{
		for(int j = 0; j < mBitmap->GetHeight(); j += dotSize)
			dc.DrawPoint(wxPoint(i, j));
	}
}

void StaticDrawController::setPen(wxDC& dc, const WxUtils::Color& color, int width) const
{
	wxPen pen(wxColour(color.getRed(), color.getGreen(), color.getBlue()), width);

	dc.SetPen(pen);
}
